package com.zhangsun.newMvvm.base.view;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import me.leefeng.promptlibrary.PromptDialog;

public abstract class BaseNoModelActivity<VDB extends ViewDataBinding> extends AppCompatActivity {

    protected VDB binding;
    private PromptDialog promptDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, getLayoutId());

        promptDialog = new PromptDialog(this);
        init(savedInstanceState);
    }

    /**
     * 获取 layout 资源id
     *
     * @return 资源id
     */
    public abstract int getLayoutId();

    /**
     * 初始化
     *
     * @param savedInstanceState savedInstanceState
     */
    public abstract void init(Bundle savedInstanceState);

    /**
     * 显示用户等待框
     *
     * @param msg 提示信息
     */
    protected void showDialog(String msg) {
        promptDialog.showLoading(msg);
    }

    /**
     * 隐藏等待框
     */
    protected void dismissDialog() {
        if (promptDialog != null) {
            promptDialog.dismiss();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (binding != null) {
            binding.unbind();
        }
    }

}
